/*
 * Graph.h
 *
 *  Created on: 20/06/2013
 *      Author: marcio
 */

#ifndef GRAPH_H_
#define GRAPH_H_


class Graph {
	long n;

	bool** edges;

public:
	Graph(long n);

	virtual ~Graph();

	void addEdge(long i, long j);

	void removeEdge(long i, long j);

	long degree(long i);

	bool hasEdge(long i, long j);
};

Graph::Graph(long n){
	this->n = n;
	edges = new bool*[n];
	for(long i = 0; i < n; i++) edges[i] = new bool[n];
}

virtual Graph::~Graph(){
	for(long i = 0; i < n; i++) delete edges[i];
	delete edges;
}

inline void Graph::addEdge(long i, long j){
	edges[i][j] = true;
	edges[j][i] = true;
}

inline void Graph::removeEdge(long i, long j){
	edges[i][j] = false;
	edges[j][i] = false;
}

inline long Graph::degree(long i){
	long deg = 0;
	for(long j = 0; j < n; j++)
		if(edges[i][j])deg++;
	return deg;
}

inline bool Graph::hasEdge(long i, long j){
	return edges[i][j];
}


#endif /* GRAPH_H_ */
